package easyway.core.utils;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.ListUtils;

/**
 * 
 * @author jiangbin
 * @date Apr 9, 2009
 */
public class CollectionUtil {

	@SuppressWarnings("unchecked")
	public static List<Integer> intFilterInsertList(List<Integer> afterRankIdList,
			List<Integer> beforeRankIdList) {
		List<Integer> tempList = ListUtils.intersection(afterRankIdList,
				beforeRankIdList);
		return ListUtils.subtract(afterRankIdList, tempList);
	}

	@SuppressWarnings("unchecked")
	public static List<Integer> intFilterDeleteList(List<Integer> afterRankIdList,
			List<Integer> beforeRankIdList) {
		return ListUtils.subtract(beforeRankIdList, afterRankIdList);
	}
	
	@SuppressWarnings("unchecked")
	public static List<String> stringFilterInsertList(
			List<String> afterRankIdList, List<String> beforeRankIdList) {
		List<String> tempList = ListUtils.intersection(afterRankIdList,
				beforeRankIdList);
		return ListUtils.subtract(afterRankIdList, tempList);
	}

	@SuppressWarnings("unchecked")
	public static List<String> stringFilterDeleteList(
			List<String> afterRankIdList, List<String> beforeRankIdList) {
		return ListUtils.subtract(beforeRankIdList, afterRankIdList);
	}
	
	/**
	 * 组装从页面传来的Map对象
	 * 
	 * @param map 分页查询助手
	 * @return
	 */
	public static Map<String, Serializable> wrapperMap(
			Map<String, Serializable> map) {
		int pageSize = PaginationSupport.PAGESIZE;
		if (!map.containsKey("pageSize")) {
			map.put("pageSize", pageSize);
		} else {
			pageSize = ((Integer) map.get("pageSize")).intValue();
		}
		if (map.containsKey("startResult")) {
			int inBound = ((Integer) map.get("startResult")) * pageSize;
			int outBound = inBound - pageSize;
			map.put("inBound", inBound);
			map.put("outBound", outBound);
		} else {
			map.put("startResult", 1);
			map.put("inBound", pageSize);
			map.put("outBound", 0);
		}
		return map;
	}
	
}
